<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('commerce_order', function (Blueprint $table) {
            $table->comment('订单');
            $table->unsignedBigInteger('id')->comment('订单号');
            $table->unsignedBigInteger('customer_id')->comment('用户ID');
            $table->unsignedBigInteger('merchant_id')->comment('商户ID');
            $table->string('customer_name', 32)->comment('客户姓名');
            $table->string('customer_phone', 16)->nullable()->comment('客户电话');
            $table->string('customer_address', 255)->nullable()->comment('客户地址');
            $table->unsignedTinyInteger('order_source')->default(1)->comment('订单来源：1-线上下单，2-现场订单');
            $table->decimal('total_amount', 15, 2)->default(0.00)->comment('订单总金额');
            $table->decimal('discount_amount', 15, 2)->default(0.00)->comment('折扣优惠金额');
            $table->decimal('minus_amount', 15, 2)->default(0.00)->comment('满减优惠金额');
            $table->decimal('actual_amount', 15, 2)->default(0.00)->comment('实付金额');
            $table->unsignedTinyInteger('payment_method')->nullable()->comment('付款方式1-银行转账,2-微信支付,3-支付宝支付,4-现金,5-其他付款方式');
            $table->timestamp('payment_time')->nullable()->comment('支付时间');
            $table->timestamp('delivery_time')->nullable()->comment('发货时间');
            $table->string('express_company', 64)->nullable()->comment('快递公司');
            $table->string('express_id', 128)->nullable()->comment('快递单号');
            $table->decimal('express_cost', 15, 2)->default(0.00)->comment('快递费用');
            $table->json('express_info')->nullable()->comment('快递信息');
            $table->unsignedTinyInteger('order_status')->default(1)->comment('订单状态：1-未支付，2-待发货，3-待收货，4-已完成，5-已取消，6-已删除');
            $table->string('cancel_reason', 255)->nullable()->comment('取消原因');
            $table->timestamp('cancel_time')->nullable()->comment('取消时间');
            $table->timestamp('finish_time')->nullable()->comment('完成时间');
            $table->text('remark')->nullable()->comment('备注');
            $table->primary('id');
            $table->index('merchant_id', 'idx_merchant_id');
            $table->index('order_status', 'idx_order_status');
            $table->datetimes();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('commerce_order');
    }
};